import random
class Bag:
  def __init__(i,lst=[],
               rx=random.randint(0,10**32)) :  # intialization
    i.sq = i.sum = i.n = 0.0; i.rx = rx; i.rank = 0
    i.max= -1*10**32
    for x in lst: i.put(x)
  def put(i,x) : # using 'x', increment some counters 
    i.n += 1 ; i.sum += x; i.sq += x*x; i.max=max(i.max,x)
  def mu(i) :  # mean
    return i.sum / i.n
  def stdev(i): # standard deviation
    return ((i.sq-((i.sum*i.sum)/i.n))/(i.n-1))**0.5
  def copy(i) :
    j=Bag(i.rx)
    j.n=i.n; j.sum=i.sum; j.sq=i.sq; j.rank = i.rank
    return j 
    return k 
  def __repr__(i) :
    return "ranked #"+str(i.rank)+' is '+ \
           str(i.rx) + ' with ' + str(i.mu())
  def __lt__(i,j): # implement bag1 < bag2
    return i.mu()<  j.mu()
  def __add__(i,j): # implement bag1 + bag2
    k=Bag("+")
    k.n=i.n+j.n; k.sum=i.sum+j.sum; k.sq=i.sq+j.sq 
    k.max = max(i.max,j.max)
    return k 
  def __sub__(i,j) : # implement bag1 - bag2
    k=Bag("-")
    k.n=i.n-j.n; k.sum=i.sum-j.sum; k.sq=i.sq-j.sq
    return k
